package com.multi.thread.chapter04.demo10;

import java.util.concurrent.locks.ReentrantLock;

/**
 *	判断是不是公平锁,ReentrantLock默认使用非公平锁
 */
public class TestIsFair {
	
	private ReentrantLock lock;

	public TestIsFair(boolean isFair) {
		lock = new ReentrantLock(isFair);
	}
	
	public void serviceMethod() {
		try {
			lock.lock();
			System.out.println("公平锁情况：" + lock.isFair());
		} finally {
			lock.unlock();
		}
	}
	
	public static void main(String[] args) {
		TestIsFair service = new TestIsFair(true);
		service.serviceMethod();
	}

}
